#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 105;
int map[maxn][maxn];
bool use[maxn];
int minn[maxn],mst=0;

int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>map[i][j];
		}
	}

	memset(minn,0x7f,sizeof minn);
	minn[1] = 0;
	
	for(int i=1;i<=n;i++){
		use[i] = false;
		if(map[1][i] != 0){
			minn[i] = map[1][i];
		}
			
	}
	use[1] = true;
	
	for(int i=1;i<n;i++){
		int k=0;
		for(int j=1;j<=n;j++){
			if((!use[j]) && minn[j]<minn[k]){
				k = j;
			}
		}
		use[k] = true;
		mst+=minn[k];
		for(int j=1;j<=n;j++){
			if((!use[j]) && map[k][j]<minn[j]){
				minn[j] = map[k][j];
			}
		}
	}
	
	
	cout<<mst<<endl;
}